<template>
  <div class="deteil">
    <div class="img-part">
      <img :src="'/img/item/' + data.src" alt v-if="data.src">
      <h1>{{data.title}}</h1>
      <p>{{data.description}}</p>
    </div>
    <div class="price-part">
      <span class="price">
        <strong>{{data.price}}</strong>元
      </span>
      <span class="origin-price">门市价{{data.originPrice}}元</span>
      <span class="buy-btn">立即购买</span>
    </div>
    <div class="sales-part">
      <li>立即退货</li>
      <li>随时退货</li>
      <li>销量{{data.sales}}</li>
    </div>
    <div class="store-part module">
      <div class="module-header">
        <h3>店家信息</h3>
      </div>
      <div class="module-body">
        <p>{{data.storeName}}</p>
        <p>{{data.storeAddress}}</p>
      </div>
      <div class="module-footer">查看{{data.storeNum}}家分店</div>
    </div>
    <div class="buy-part module">
      <div class="module-header">购买须知</div>
      <div class="module-body">
        <h3>有效日期</h3>
        <p>{{data.validateTime}}</p>
        <h3>使用日期</h3>
        <p>{{data.useTime}}</p>
        <h3>使用规则</h3>
        <p v-for="(item,index) in data.rules" :key="index">{{item}}</p>
      </div>
    </div>
  </div>
</template>

<style lang="scss">
@import "../base.scss";
.deteil {
  .img-part {
    position: relative;
    color: white;
    img {
      width: 100%;
      display: block;
    }
    h1,
    p {
      position: absolute;
      left: 15px;
      bottom: 15px;
      font-size: 16px;
    }
    h1 {
      bottom: 40px;
      font-size: 24p;
    }
  }
  .price-part {
    background-color: #fff;
    padding: 0 10px;
    height: 60px;
    line-height: 60px;
    border-bottom: 1px solid #ccc;
    .price {
      color: $navColor;
      margin-right: 6px;
      strong {
        font-size: 36px;
      }
    }
    .buy-btn {
      padding: 6px 10px;
      color: white;
      background-color: #f40;
      margin-top: 16px;
      font-size: 12px;
      line-height: 1;
      float: right;
    }
  }

  .sales-part {
    @include clearfix;
    background-color: #fff;
    li {
      width: (100%/2);
      color: yellowgreen;
      padding: 10px;
      box-sizing: border-box;
      float: left;
      line-height: 20px;
      height: 30px;
      &:last-child {
        color: #000;
      }
    }
  }
  .module {
    background-color: #fff;
    margin-top: 10px;
    .module-header {
      font-size: 20px;
      margin: 0 10px;
      border-bottom: 1px solid #ccc;
      padding: 15px 0 10px;
    }
    .module-body {
      padding: 15px 10px;
      font-size: 16px;
      line-height: 28px;
      h3 {
        font-size: 18px;
        color: #f40;
        padding: 12px 0 8px;
        font-weight: normal;
      }
    }
    .module-footer {
      color: skyblue;
      font-size: 16px;
      padding: 10px 0px 15px;
      margin: 0 10px;
      border-top: 1px solid #ccc;
    }
  }
}
</style>

<script>
export default {
  data() {
    return {
      data: {}
    };
  },
  methods: {
    updateData() {
      let { params } = this.$route;
      this.$http
        .get("/data/product.json", { params })
        .then(({ data }) => (this.data = data));
    }
  },
  created() {
    this.updateData();
  },
  watch: {
    $route($route) {
      this.updateData();
    }
  }
};
</script>
